#! /usr/bin/env python
# coding=utf-8


# 对给定路径中每个fastq文件运行 sh 脚本 run_iso_pipline.sh test.fastq  cluster 192 isoseq

from Bio import SeqIO
from argparse import RawTextHelpFormatter

import os
import sys
import argparse
import shutil
import time

parser = argparse.ArgumentParser(
    description='''
    对分片的fastq文件运行run_iso_pipline.sh
    用法：
    
    ''',formatter_class=RawTextHelpFormatter)



parser.add_argument('-i',
                help='分片的fastq文件路径')

parser.add_argument('-t',
                help='cpu数, 默认为8')

parser.add_argument('-s',
                help='seq 类型 isoseq ccs ont')




args = parser.parse_args()



if not args.i or not args.s:

    parser.print_help()

    sys.exit()

if not args.t:
    num_threads = 8
else:
    num_threads = int(args.t)




infile = args.i 
seq_type = args.s


for i in os.listdir(infile):
    if i.split('.')[-1] in ['fastq','fq']:
        outfolder = infile+'/'+'.'.join(i.split('.')[:-1])
        target_file = infile+'/'+i
        print('work on %s' % target_file )
        os.system('run_iso_pipline.sh %s %s %s %s' %(target_file, outfolder, num_threads, seq_type))



